package com.karaoke.android.kege.vm

import android.databinding.ObservableArrayList
import android.databinding.ObservableList
import com.karaoke.android.data.NetworkTools
import com.karaoke.android.data.domain.Song
import com.karaoke.android.data.onIO
import com.karaoke.android.data.onUI
import com.karaoke.android.kege.BR
import com.karaoke.android.kege.R
import com.karaoke.android.kege.adapter.BangListAdapter
import com.karaoke.android.library.databind.ItemBinding
import com.karaoke.android.library.mvvm.FragmentViewModel
import com.trello.rxlifecycle.kotlin.bindToLifecycle

/**
 * Created by allen on 2017/4/23.
 */

class BangViewModel : FragmentViewModel()
{
    val newAdapter = BangListAdapter()
    val hotAdapter = BangListAdapter()
    val recommendAdapter = BangListAdapter()
    val newSongs: ObservableList<Song> = ObservableArrayList<Song>()
    val hotSongs: ObservableList<Song> = ObservableArrayList<Song>()
    val recommendSongs: ObservableList<Song> = ObservableArrayList<Song>()
    val songBindings: ItemBinding<Song> = ItemBinding.of<Song>(BR.viewModel, R.layout.bang_item)

    override fun onInitLoad()
    {
        super.onInitLoad()
        NetworkTools.songService.getHotSongs().onIO()
                .bindToLifecycle(this)
                .onUI({ hotSongs.addAll(it) }, {})
        NetworkTools.songService.getNewSongs().onIO()
                .bindToLifecycle(this)
                .onUI({ newSongs.addAll(it) }, {})
        NetworkTools.songService.getRecommends().onIO()
                .bindToLifecycle(this)
                .onUI({ recommendSongs.addAll(it) }, {})
    }
}
